﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Linq;
using System.Text;

namespace BeatingMole
{
    /// <summary>
    /// Nguyễn Đặng Anh Duy
    /// MSSV : 11100204
    /// Email : itc.anhduy@gmail.com
    /// <summary>
    class CBusExit
    {
        #region "Variable"
        CInfoExit InfoExit;
        ContentManager _Content;
        Vector2 PosExit;
        private bool _isEnableBusMenu;
        bool IsReady = false;

        MouseState MouseCur;
        MouseState MousePre;
        #endregion

        #region "Properties"
        public bool IsEnableBusMenu
        {
            set { _isEnableBusMenu = value; }
            get { return _isEnableBusMenu; }
        }
        #endregion

        #region "Constructor"
        public CBusExit(ContentManager content)
        {
            _Content = content;
            InfoExit = new CInfoExit(_Content);
            PosExit = new Vector2(0, 480);
        }
        #endregion

        #region "Method"
        /// <summary>
        /// Quản lý lên xuống
        /// </summary>
        private void ManagerExit()
        {
            if (IsEnableBusMenu == false)
            {
                PosExit.Y -= CGlobalVariable.SpeedTranslate;
                if (PosExit.Y <= 0)
                {
                    PosExit.Y = 0;
                    IsReady = true;
                }
            }
            else
            {
                PosExit.Y += CGlobalVariable.SpeedTranslate;
                if (PosExit.Y >= 480)
                {
                    PosExit.Y = 480;
                }
            }
        }

        private void YesOrNo()
        {
            MouseCur = Mouse.GetState();
            if (MouseCur.LeftButton == ButtonState.Pressed && MousePre.LeftButton == ButtonState.Released)
            {
                if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(InfoExit.RecBtnYes))
                {
                    new Microsoft.Xna.Framework.Game().Exit();
                }

                if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(InfoExit.RecBtnNo))
                {
                    IsEnableBusMenu = true;
                    IsReady = false;
                    CGlobalVariable.IsEnableMenu = true;
                    CGlobalVariable.PosMenuBack = CGlobalVariable.PositionMenu.TopBack;
                }
            }
            MousePre = MouseCur;
        }
        public void UpdateExit(GameTime gameTime)
        {
            ManagerExit();
            if (IsReady == true)
            {
                YesOrNo();
            }
        }

        public void DrawExit(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(InfoExit.BgExit, PosExit, Color.White);
            //spriteBatch.Draw(InfoExit.BgBlack, new Rectangle(0, Convert.ToInt32(100 + PosExit.Y), 800, 380), Color.Black * 0.75f);
            spriteBatch.Draw(InfoExit.BgBlack, PosExit, Color.Black * CGlobalVariable.Opacity);
            spriteBatch.Draw(InfoExit.BtnYes, new Vector2(100, 225 + PosExit.Y), Color.White);
            spriteBatch.Draw(InfoExit.BtnNo, new Vector2(450, 225 + PosExit.Y), Color.White);
        }
        #endregion
    }
}
